package com.mrx.commons.task;

import com.mrx.commons.model.dto.Result;
import com.mrx.commons.task.model.TaskCreateVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author Mr.X
 * @since 2023-12-08 13:36
 **/
@RestController
public class XScheduleTaskController {

    @Resource
    private ScheduleTaskService scheduleTaskService;

    @PostMapping("/task/create")
    public Result<?> createTask(@RequestBody TaskCreateVO vo) {
        scheduleTaskService.createTask(vo);
        return Result.success();
    }

    @PutMapping("/task/start")
    public Result<?> startTask(@RequestParam String taskName) throws Exception {
        String result = scheduleTaskService.runTask(taskName).get(5, TimeUnit.SECONDS);
        return Result.success(result);
    }

}
